#include <iostream>
using namespace std;

/*
class Person{
public:
    void Print() const{
        cout << "name:" << _name << endl;
        cout << "id:" << _age << endl;
    }

    static void func(){
        cout << "Person" << endl;
    }

    string _name = "Lu";
    int _age = 18;
};

class Student:public Person{
public:
    int _stuid = 22033;
};

class Teacher:public Person{
protected:
    int _jobid = 16033;
};

class Worker:public Person{
public:
    static void func(){
        cout << "Worker" << endl;
    }

    int _age = 33;
};

void test1(){
    Student().Print();
    cout << "student_id:" << Student()._stuid << endl;
    Teacher().Print();
}

void test2(){
    cout << Worker()._age << endl;
    cout << Worker().Person::_age << endl;

    Worker worker;
    cout << worker.Person::_age << endl;
}

void test3(){
    Worker::func();
    Worker().Person::func();
}
*/

class Person{
public:
    Person(const char* name = "Lu")
    :_name(name){
        cout << "Person()" << endl;
    }

    Person(const Person& p)
    :_name(p._name){
        cout << "Person(const Person& p)" << endl;
    }

    Person& operator=(const Person& p){
        if (this != &p){
            _name = p._name;
            cout << "Person operator=(const Person& p)" << endl;
        }
        return *this;
    }

    ~Person(){
        cout << "~Person()" << endl;
    }

    string _name;
};

class Student : public Person{
public:
    Student(const char* name = "hang", int num = 22)
    : Person(name)
    ,_num(num){
        cout << "Student()" << endl;
    }

    Student(const Student& s)
    : Person(s)
    ,_num(s._num){
        cout << "Student(const Student& s)" << endl;
    }

    Student& operator=(const Student& s){
        if (this != &s){
            Person::operator=(s);
            _num = s._num;
            cout << "Student& operator=(const Student& s)" << endl;
        }
        return *this;
    }

    //子类析构函数完成时，会自动调用父类析构函数（不需要手动调父类析构函数），保证先析构子类再析构父
    ~Student(){
        cout << "~Student()" << endl;
    }

    int _num;
};

void test4(){
    cout << Person()._name << endl;
    cout << Student()._name << endl;
    cout << Student()._num << endl;
}
int main() {
    test4();
    return 0;
}
